#!/usr/bin/perl
#Programmer: Rory Carmichael
#Purpose: Fix error in which second line of a rare codon cluster file is already data

my %col_hist = ();
my $numlines = 0;
my $numpeaks = 0;

my $infile = $ARGV[0];
chomp $infile;
my $tmpfile = $infile . ".tmp";
open(IF, "$infile");
open(OF, ">$tmpfile");
my $firstline = <IF>;
print OF $firstline;
my $secondline = <IF>;
if($secondline =~ /^[0-9|\-|\s]*$/) {
	print STDERR "$infile is badly formatted.\n";
	print STDERR "BAD LINE 2: $secondline\n";
	print OF ">\n";
} else {
	print OF $secondline;
}
foreach my $line (<IF>) {
	if($line !~ /^[0-9|\-|\s]*$/) {
		print STDERR "$infile is badly formatted beyond second line. Giving up\n";
		print STDERR "BAD LINE " . $numlines + 3 . ": $line\n";
		close(IF);
		close(OF);
		`rm $tmpfile`;
		exit 1;
	} else {
		print OF $line;
	}
}
close(OF);
close(IF);
`mv $tmpfile $infile`;

